package com.hyh.mall.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

//@RestController
@Controller
public class HelloController {

    @RequestMapping(value = "/hello",produces = "aplication/json;charset=utf-8")
    public String index(HttpServletRequest req, HttpServletResponse res) {
        res.setContentType("text/plain;charset");
        return "Hello World";
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
        String str = new String("中".getBytes("utf-8"),"utf-8");
        System.out.println(str);
    }

    @GetMapping("/")
    public String index(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host", "http://blog.didispace.com");

        // return模板文件的名称，对应src/main/resources/templates/index.html
        return "index";
    }
}
